package util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;

import org.ejml.data.DenseMatrix64F;
import org.ejml.ops.MatrixIO;

public class ResultEstimator {

	public static void main(String[] args){
		DenseMatrix64F resultMatrix = estimator("output/NBresult", 4);
		PrintStream ps;
		try {
			ps = new PrintStream("output/NBresultMatrix.txt");
			MatrixIO.print(ps, resultMatrix, 5, 2);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static DenseMatrix64F estimator(String resultFile, int numOfCategories){
		DenseMatrix64F resultMatrix = new DenseMatrix64F(numOfCategories, numOfCategories);
		
		try {
			BufferedReader br = new BufferedReader(new FileReader(resultFile));
			for(String curLine = br.readLine(); curLine != null; curLine = br.readLine()){
				String[] indexes = curLine.split(" ");
				int rightIndex = Integer.parseInt(indexes[0]);
				int predictIndex = Integer.parseInt(indexes[1]);
				resultMatrix.set(rightIndex, predictIndex, resultMatrix.get(rightIndex, predictIndex)+1);
			}
			br.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return resultMatrix;
	}
}
